import { zwlogPvGlobal } from '@/utils/buriedPoint';
import { onMounted, onUnmounted } from 'vue';
import { useRoute } from 'vue-router';
import { useGlobalStore, useAuthStore } from '@/stores';

const zwlog = new ZwLog();
export default function () {
	const route = useRoute();
	// console.log(route);

	const enterPageTime = new Date();
	let responseTime = null;
	onMounted(() => {
		responseTime = new Date();
	});
	onUnmounted(() => {
		const { userInfo } = useAuthStore();

		const { contactName, zlbUserId } = userInfo;

		const duration = (new Date() - responseTime) / 1000 + '秒';

		// const zwlog = new ZwLog({
		// 	_user_id: zlbUserId,
		// 	_user_nick: contactName,
		// });

		// console.log(zwlog);

		zwlog.onReady(() => {
			zwlog.sendPV({
				_user_id: zlbUserId,
				_user_nick: contactName,
				miniAppId: '2002319540',
				miniAppName: '博悦游',
				log_status: '02',
				Page_duration: duration,
				pageId: 'home',
				pageName: '首页',
			});
		});
		return;

		zwlog.onReady(function () {
			// console.log('zwlog准备');
			zwlog.sendPV(pvParams); //发送埋点信息
			// console.log('zwlog已发送', pvParams);
			delete pageLogMap[path]; //清空埋点集合 避免重复
		});
		return;
		zwlogPvGlobal({
			url: route.path,
			pagename: route.name,

			enterPageTime,
			// loadTime: this.loadTime,
			// responseTime: this.responseTime,
			leavePageTime: new Date(),
		});
	});
}
